<template>
    <div class="container-fluid" style="background: #fff">
        <div class="row page-title">
            <div class="col-xs-11">
                <h1>推送</h1>
            </div>
        </div>
        <el-form :model="form" ref="form" :rules="rules" label-width="150px">
            <!-- <el-form-item class="hr"></el-form-item> -->
            <el-form-item label="推送内容：" prop="Content">
                <el-input v-model="form.Content" placeholder="请输入推送内容" type="textarea" clearable style="width:60%;"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button size="medium" type="primary" @click="save">确定推送</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                user:JSON.parse( sessionStorage.getItem('user')),
                formLabelWidth: '25%',
                form: {},
                rules:{
                    Content:[
                        { required: true, message: '请输入推送内容', trigger: 'blur' },
                    ]
                },
                addUrl:this.urlConfig+'/api/MessageSend/PostMessagesend',
            }
        },
        components: {
        },
        mounted() {
        },
        methods:{
            validateFun:function(){
                var errorInfo='';
                for(var i=0;i<1;i++){
                    this.$refs.form.validateField((['Content'][i]),(re)=>{
                        errorInfo+=re+(re==''?'':', ');
                    })
                }
                return errorInfo;
            },
            save:function(){
                this.$confirm('确定推送?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    var errorInfo=this.validateFun();
                    if(!errorInfo){
                        this.form.SendUserId = this.user.Id;
                        this.$http.post(this.addUrl,this.form,{
                            emulateJSON: true
                        }).then(function(res) {
                            if(res.body["Code"] == "200") {
                                this.$notify({title: '成功',message: '推送成功',type: 'success'});
                            }else{
                                this.$notify.error({title: '错误',message:res.body["Message"]});
                            }
                        });
                    }else{
                        this.$notify({title: '警告',message: errorInfo,type: 'warning',duration:1200});
                        return false;
                    }
                }).catch(() => {});
            }
        }
    }
</script>
<style>
    .headerbg{
        background-color: #f4f3f3 !important;
    }
</style>
